//
//  DKFriendThrendsViewController.m
//  BS1
//
//  Created by 丁侃 on 16/4/23.
//  Copyright © 2016年 丁侃. All rights reserved.
//

#import "DKFriendThrendsViewController.h"
#import "DKLoginViewController.h"

@interface DKFriendThrendsViewController ()

@end

@implementation DKFriendThrendsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = DKRandomColor;
    

    //将设置导航栏内容抽取
    [self setupNavContent];
    
    //富文本应用
    [self setupAttribute];
    
    //图文混排
    [self setAttributeLabel];
}

//通过富文本属性,来设置标题
-(void)setupAttribute
{
    //只有才能设置富文本属性,所以这里不能选择NSString,而是要创建一个label类型控件
    //创建UILabel对象
    UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 40)];
    titleLabel.numberOfLines = 0;
    titleLabel.textAlignment = NSTextAlignmentCenter;
    
    NSString *title = @"111111\n2222222222";
    NSDictionary *headdic = @{
                          NSFontAttributeName:[UIFont systemFontOfSize:12.0],
                          NSForegroundColorAttributeName:[UIColor blackColor]
                          
                          };
    NSMutableAttributedString *att = [[NSMutableAttributedString alloc]initWithString:title];
    //NSMutableAttributedString才能只用addAtt..的方法,不可变的不能设置
    [att addAttributes:headdic range:NSMakeRange(0, 6)];
    NSDictionary *endDic = @{
                             NSFontAttributeName:[UIFont systemFontOfSize:15.0],
                             NSForegroundColorAttributeName:[UIColor redColor]
                             };
    [att addAttributes:endDic range:NSMakeRange(6, title.length - 6)];
    titleLabel.attributedText = att;
    self.navigationItem.titleView = titleLabel;
}


//通过富文本来实现图文混排
-(void) setAttributeLabel
{
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(100,100, 100, 44)];
    
    NSDictionary *one = @{
                          NSFontAttributeName:[UIFont systemFontOfSize:10.0],
                          NSForegroundColorAttributeName:[UIColor blackColor]
                          };
    //创建前段富文本
    NSMutableAttributedString *first = [[NSMutableAttributedString alloc] initWithString:@"111111" attributes:one];
    //创建附加对象
    NSTextAttachment *attachment = [[NSTextAttachment alloc]init];
    attachment.image = [UIImage imageNamed:@"header_cry_icon"];
    attachment.bounds = CGRectMake(0, 0, 25, 25);
    //富文本的图片
    NSAttributedString *next = [NSMutableAttributedString attributedStringWithAttachment:attachment];
    //创建尾部富文本
    NSAttributedString *end = [[NSAttributedString alloc]initWithString:@"2222222" attributes:one];
    //拼接
    [first appendAttributedString:next];
    [first appendAttributedString:end];
    label.attributedText = first;
    [self.view addSubview:label];
}


//将设置导航栏内容抽取
-(void)setupNavContent
{
    //添加左按钮
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem dk_itemWithTarget:self ation:@selector(friendsClick) ImageNameNormal:@"friendsRecommentIcon" imageNameHighlighted:@"friendsRecommentIcon-click"];
}


- (IBAction)logIn:(id)sender {
    
    //modal出登录界面
    DKLoginViewController *loginVc = [[DKLoginViewController alloc]init];
    [self presentViewController:loginVc animated:YES completion:nil];
    
}

-(void)friendsClick
{
DKFunc
}


@end
